(function (window, $, undefined) {
  'use strict';

  main(function () {

    var $tableInfoSetting = $('#table-infoSetting');
    util.jqGrid($tableInfoSetting, {
      url: '/json/test.json',
      datatype: 'json',
      autowidth: true,
      height: $(window).height() - 320,
      multiselect: true,
      multiboxonly: true,
      // shrinkToFit: false,
      colModel: [
        { name: '_id', key: true, hidden: true },
        { label: '名称', name: '', width: 100 },
        { label: '状态', name: '', width: 100 },
        { label: '素材地址', name: '', width: 100 },
        { label: '时段', name: '', width: 120 },
        { label: '有效期', name: '', width: 150 }
      ],
      pager: '#pager-infoSetting'
    });

    // 新增操作
    $('#btn-add').click(function () {
      $('#layer-infoSetting-add').find(':input').removeAttr('disabled');
      util.layerOpen({
        title: '新增消息模板',
        content: $('#layer-infoSetting-add'),
        btn: ['取消', '确定'],
        cancel: function (index) {
          layer.confirm('确定退出当前页面？', {
            btn: ['确定', '再想一想'],
            yes: function (idx) {
              layer.close(index);
              layer.close(idx);
            }
          });
          return false;
        }
      });
    });

    // 查看
    $('#btn-view').click(util.oneCheck($tableInfoSetting, function (id) {
      // util.ajax('http://192.168.1.110:16101/auto/getAuto', {
      //   kid: id,
      // }, 'GET', util.resCallback(function (res) {
      //   var data = res.data;
      //   util.fillForm('#form-vehicle-edit', data);
      // }));

      util.layerOpen({
        title: '修改广告',
        content: $('#layer-infoSetting-view'),
        btn: ['确认', '取消'],
        cancel: function (index) {
          layer.confirm('确定退出当前页面？', {
            btn: ['确定', '再想一想'],
            yes: function (idx) {
              layer.close(index);
              layer.close(idx);
            }
          });
          return false;
        }
      });
    }));

    // 修改
    $('#btn-edit').click(util.oneCheck($tableInfoSetting, function (id) {
      // util.ajax('http://192.168.1.110:16101/auto/getAuto', {
      //   kid: id,
      // }, 'GET', util.resCallback(function (res) {
      //   var data = res.data;
      //   util.fillForm('#form-vehicle-edit', data);
      // }));

      util.layerOpen({
        title: '修改广告',
        content: $('#layer-infoSetting-edit'),
        btn: ['确认', '取消'],
        cancel: function (index) {
          layer.confirm('确定退出当前页面？', {
            btn: ['确定', '再想一想'],
            yes: function (idx) {
              layer.close(index);
              layer.close(idx);
            }
          });
          return false;
        }
      });
    }));


  });


})(window, jQuery);
